import java.util.*;

public class Test {

    //找出10w个数据中第一个重复的值
    public static void findNum(int[] array){
        Set<Integer> set = new HashSet<>();
        for (int x : array) {
            if(!set.contains(x)){
                set.add(x);
            }else{
                System.out.println(x);
            }
        }
    }

    //将10w个数据去重
    public static void removeNum(int[] array){
        Set<Integer> set = new HashSet<>();
        for (int x : array) {
            set.add(x);
        }
        System.out.println(set);
    }

    //统计10w个数据当中，重复的数据出现的次数
    public static int statistics(int[] array){
        Set<Integer> set = new HashSet<>();
        int count = 0;
        for (int x : array) {
            if(!set.contains(x)){
                set.add(x);
            }else{
                count++;
            }
        }
        return count;
    }

    //使用map

    public static void main1(String[] args) {
        int[] array = {1,0,0,0,0,1,1,2,7,7,7,9};
        statistics2(array);
    }

    public static void statistics2(int[] array){
        Map<Integer,Integer> map = new HashMap<>();
        for (int i = 0; i < array.length ; i++) {
            if(map.get(array[i]) == null){
                map.put(array[i],1 );
            }else{
                int val = map.get(array[i]);
                map.put(array[i],val + 1 );
            }
        }

        for (Map.Entry<Integer,Integer> entry : map.entrySet()) {
            System.out.println("数字" + entry.getKey() + "出现次数：" + entry.getValue()+ "次");
        }
    }

    public static void main(String[] args) {
        String[] world = {"i", "love", "leetcode", "i", "love", "coding"};
        Work work = new Work();
        List<String> ret =  work.topKFrequent3(world,3);
        System.out.println(ret);
    }

}
